import request from '../utils/request'
import { USER } from './constanst'

const userLogin = user => request({
  url: USER.LOGIN_API,
  method: 'POST',
  data: {
    username: user.username,
    password: user.password
  }
})

const dtsend = (token, data) => request({
  url: USER.DTdisplay_API,
  method: 'POST',
  headers: {
    Authorization: token
  },
  data
})

const currentUser = token => request({
  url: USER.GETUSER_API,
  method: 'GET',
  headers: {
    Authorization: token
  }
})
// 修改头像
const ModifyAvatar = (token, data1) => request({
  url: USER.ModifyAvatar_API,
  method: 'POST',
  headers: {
    Authorization: token
  },
  data: {
    avatar: data1
  }

})

// 更新真实姓名
const userinfo = (token, id, nickname, email) => request({
  url: USER.Truename_API,
  method: 'POST',
  headers: {
    Authorization: token
  },
  data: {
    id: id,
    nickname: nickname,
    email: email
  }

})

// 修改密码
const UpdatePassword = (token, pwd1, pwd2) => request({
  url: USER.UpdatePassword_API,
  method: 'POST',
  headers: {
    Authorization: token
  },
  data: {
    username: pwd1,
    password: pwd2
  }

})

// 注册新用户
const Register = (username, pwd) => request({
  url: USER.Register_API,
  method: 'POST',
  // headers: {
  //   Authorization: token
  // },
  data: {
    username: username,
    password: pwd
  }

})

export {
  userLogin,
  currentUser,
  dtsend,
  ModifyAvatar,
  UpdatePassword,
  Register,
  userinfo
}
